package com.yixun.qfbao.controller;

import com.yixun.qfbao.api.service.CustomerApiService;
import com.yixun.qfbao.api.service.DueRemainderConfigService;
import com.yixun.qfbao.api.service.JobService;
import com.yixun.qfbao.api.service.WeiXinDemoService;
import com.yixun.qfbao.response.BaseResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@Controller
@ResponseBody
@RequestMapping("/jobTest")
public class JobTestController {

    private static final Logger logger = LoggerFactory.getLogger(JobTestController.class);

    @Autowired
    private JobService jobService;

    @Autowired
    private DueRemainderConfigService dueRemainderConfigService;

    @Autowired
    private CustomerApiService customerApiService;

    @Autowired
    private WeiXinDemoService weiXinDemoService;

    @PostMapping("/overTradeTimeJob")
    public void overTradeTimeJob(){
        jobService.overTradeTimeJob();
    }

    @PostMapping("/overReporValidTimeJob")
    public void overReporValidTimeJob(){
        int count = jobService.overReporValidTimeJob();
        logger.info("over report valid time count: {}", count);
    }

    /**
     * 调用需谨慎，目前未处理有关分销小程序内容
     */
    @PostMapping("/sendDueRemainderInfo")
    public void sendDueRemainderInfo(){
    	// dueRemainderConfigService.sendDueRemainderInfo();
    }
    
    /**
     * 调用需谨慎，目前未处理有关分销小程序内容
     */
    @PostMapping("/sendToBeDueRemainderInfo")
    public void sendToBeDueRemainderInfo(){
    	dueRemainderConfigService.sendToBeDueRemainderInfo();;
    }

    @Deprecated
    @PostMapping("/initCPCustomer")
    public String initCPCustomer(@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date initStart, @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date initEnd){
        return "规则变更,功能不可用";
        // customerApiService.initCPCustomer(initStart, initEnd);
    }

    @PostMapping("getWechatUser")
    public void getWechatUser(){
        weiXinDemoService.getWechatUser();
    }

    /**
     * 合并经纪人客户
     * 因规则变更,现需要合并经纪人名下的客户
     * 主要变更点为: 隐号客户相同号码视为一个人
     * jira: https://jira.qiaofangyun.com/browse/QDW-952
     */
    @PostMapping("/mergeAgentCustomer")
    public BaseResponse<String> mergeAgentCustomer(){
        BaseResponse<String> response = new BaseResponse<>();
        customerApiService.mergeAgentCustomer();
        return response;
    }

    @PostMapping("/sendM2Again")
    public BaseResponse<String> sendM2Again(){
        BaseResponse<String> response = new BaseResponse<>();
        jobService.sendM2Again();
        return response;
    }

}
